import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('piniaCart', () => {
    let piniaCart = ref([])
    let piniaAddCart = (detailData, goods_id) => {
        let username = localStorage.getItem('username')
        let pdCart = piniaCart.value.find(item => item.goods.goods_id)
        if (pdCart) {
            pdCart.value++
        }
        else {
            piniaCart.value.push({
                username: username,
                id: Math.floor(Math.random() * 100000),
                checked: true,
                goods: detailData,
                number: 1
            })
        }
    }

    return { piniaCart, piniaAddCart }
},
    {
        persist: true,
    },
)